package com.example.itcacp.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 静态资源映射：确保前端能通过 URL 访问上传的图片
 * */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射本地文件路径到web访问路径
        registry.addResourceHandler("/avatar/**")
                .addResourceLocations("file:" + System.getProperty("user.dir") + "/src/main/resources/image/avatar/");

        // 添加内容图片路径映射
        registry.addResourceHandler("/content/**")
                .addResourceLocations("file:" + System.getProperty("user.dir") + "/src/main/resources/image/content/");

        // 添加缓存图片路径映射
        registry.addResourceHandler("/temp/**")
                .addResourceLocations("file:" + System.getProperty("user.dir") + "/src/main/resources/image/temp/");
    }
}
